#!/bin/bash

# 该脚本用于更新系统并升级 Ubuntu内核。
# 作者: AMD FAE huangsheng
# 版本: 1.0

# 检测操作系统是否为 Ubuntu
if [[ $(lsb_release -is) != "Ubuntu" ]]; then
    echo "该脚本仅适用于 Ubuntu 系统。"
    exit 1
fi

sudo apt update && sudo apt upgrade -y
sudo apt -y upgrade linux-image-generic

sudo cp /etc/default/grub /etc/default/grub.bak
sudo sed -i '/^GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"/d' /etc/default/grub

sudo update-grub
echo "不停按shift，进入Ubuntu高级选项，选择最新版本内核，进入系统。"
echo "卸载内核"
echo "dpkg --list | grep linux-image"
echo "sudo apt remove --purge linux-image-5.15.0-122-generic"
echo "sudo apt remove --purge linux-headers-5.15.0-122-generic"
echo "sudo apt autoremove --purge"
echo "系统将在 5 秒后重启..."
sleep 5
sudo reboot

